package com.qfedu.edu.handler;

import com.qfedu.edu.context.Context;
import com.qfedu.edu.result.R;
import com.qfedu.edu.utils.HttpResponseUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wangchen
 * @title: MyLogoutHandler
 * @projectName cd-fy-2401-third-project-parent
 * @description: 退出的处理
 * @date 2024/9/14  9:25
 */
@Component
public class MyLogoutHandler implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        //将内存中的权限和角色信息给清除
        //首先第一步拿到这个token信息
        String token = request.getHeader("token");
        Context.getRoleAndPermMap().remove(token);
        //告诉前端退出成功
        R ok = R.ok();
        HttpResponseUtils.sendResponse(response, ok);
    }
}
